#include "Frm04.h"

Frm04::Frm04(HmiApp* app, STTWidget *par, const string& id, const string& desc) : STTPage(app->getRuntime(), par, id, desc) {
	hmiApp = app;
}

Frm04::~Frm04() {
}

void Frm04::onInit() {

}

void Frm04::createParts() {
	setMainArg(0, 0, 1024, 600);
	setMainStyle(0, 0xffffff, 0xffffff, 0, 255, 0, 0xc0c0c0);

	/*----------------------------- Text : wMText1                       -----------------------------*/
	wMText1 = new STTTextArea(p_rt, this, "wMText1");
	wMText1->setMainArg(193, 6, 537, 82, false, true, TextAlign::CENTER, -1, -1, -99999999, 99999999, false);
	wMText1->setMainStyle(7, 0xffffff, 0xffffff, 0, 2, 0xc0c0c0, 27, 28, 4, 4, 255);
	wMText1->setPlaceholderText("")->setMaxLength(0)->setAcceptedChars("")->setImeMode(IME::UC);
	wMText1->setFont(0x0, 16, "文泉驿微米黑", 0);
	wMText1->setText("维语键盘（需要维语字体）");

	/*called after widget created.*/

	return; //createParts END
}

#define SYMBOL_BACKSPACE "\xEF\x95\x9A" //退格

#define SYMBOL_CLOSE "\xEF\x80\x8D" //关闭

#define SYMBOL_OK "\xEF\x80\x8C" //确认

#define SYMBOL_NEWLINE "\xEF\xA2\xA2"//换行

#define SYMBOL_HOME "\xEF\x80\x95" //HOME

#define SYMBOL_RIGHT "\xEF\x81\x94" //向右

#define SYMBOL_LEFT "\xEF\x81\x93" //向左

#define SYMBOL_KEYBOARD "\xEF\x84\x9C" //输入法选择

static const char *keymap[] = { "ئا", "ئە", "ئو", "ئۇ", "ئۆ", "ئۈ", "ئې", "ئى", "ب", "پ", "backspace", "\n",
		"ت", "ج", "چ", "خ", "د", "ر", "ز", "ژ", "س","ش","enter", "\n",
		"غ", "ف", "ق", "ك", "گ", "ڭ","ل", "م", "ن", "ھ", "\n",
		"ۋ", "ي",  "\n",
		SYMBOL_CLOSE, SYMBOL_LEFT, "space", SYMBOL_RIGHT,
		SYMBOL_OK, "" };

static uint16_t ctrlmap[] = {
	1,1,1,1,1,1,1,1,1,1,1|0x0080
	,1,1,1,1,1,1,1,1,1,1,1|0x0080
	,1,1,1,1,1,1,1,1,1,1
	,1,1
	,1|0x0080,1|0x0080,1,1|0x0080,1|0x0080
};

static bool func_customerkey(const char* txt) {
	cout<<txt<<endl;
	if(strcmp(txt,"space")==0) {
		cout<<"todo yourself handler"<<endl;
		return true;//返回true，则不再做内置功能(往文本框增加按键值)
	}
	return false;//返回false，则会调用默认的往文本框中增加内容
}

void Frm04::onLoad() {
	wMText1->setImeMode(8);
	//5.1.设为布局修改模式
	wMText1->setImeMode(8);
	//5.2.设置键盘按钮表
	STTTextArea::setCustomKey(keymap);
	//5.3.设置键盘按钮属性表
	STTTextArea::setCustomKeyCtrl(ctrlmap);
	//5.3.设置键盘字体(默认是英文字，其他语言文字不能正常显示)
	STTTextArea::setCustomKeyFont(fm->getFont("文泉驿微米黑", 16, 0));
	//5.4.设置自定义键盘处理函数
	STTTextArea::setCustomKeyHandler(func_customerkey);
	//5.5.设置特殊键
	STTTextArea::setCustomSpecialKey("backspace",SYMBOL_BACKSPACE,0);
	STTTextArea::setCustomSpecialKey("enter",SYMBOL_NEWLINE,1);
	//STTTextArea::setCustomSpecialKey("space"," ",2);//"space"键转换为" "
}

bool Frm04::onClosing() {
	return true;
}

void Frm04::onDispose() {

}

